<template>
	<!-- 客户管理 -->
	<view class="vehicle customerManagement">
		<u-navbar title="" :background="background" title-color="#fff" back-icon-color="#fff">
			<view class="slot-wrap">
				<view class="u-navber-search" @click="cusQueryClick">
					<text class="iconfont iconsousuo"></text>
					{{cusName}}
				</view>
			</view>
		</u-navbar>
		<view class="vehicle-bottom">
			<view class="vehicle-car">
				<!-- <view class="vehicle-car-box">
					<text class="vehicle-stick"></text>
					<text class="vehicle-car-details">车辆详情</text>
				</view> -->
				<view class="vehicle-add" @click="addCar">
					<text class="iconfont icontianjia"></text>
					<text class="vehicle-add-button">添加</text>
				</view>
			</view>
			<!-- 内容 -->
			<view class="vehicle-content-box" v-if="vehicleArrList.length!=0" v-for="(item,index) of vehicleArrList" :key="index">
				<!--  -->
				<view class="vehicle-car vehicle-content">
					<!-- 名称 -->
					<text class="vehicle-car-details vehicle-carNumber" ref="carNumbers">{{item.ORMTB410CA00}}</text>
				</view>
				<!--  -->
				<view class="vehicle-content-bottom">
					<view class="vehicle-carName-phone">
						<view class="vehicle-carName">
							<text class="vehicle-phone">简称:</text>
							<text class="vehicle-input-one">{{item.ORMTB410CA01}}</text>
						</view>
					</view>
					<view class="vehicle-carName-phone">
						<view class="vehicle-carName">
							<text class="vehicle-phone">联系方式:</text>
							<text class="vehicle-input-one">{{item.ORMTB410CA02}}</text>
						</view>
					</view>
					<!-- <view class="vehicle-carName-phone">
						<view class="vehicle-carName">
							<text class="vehicle-phone">授信额度:</text>
							<text class="vehicle-input-one">{{item.SETTB402CA03}}</text>
						</view>
					</view> -->
					<!--  -->
					<view class="vehicle-button-box">
						<view class="vehicle-add vehicle-button-margin" @click="modify(item)" style="background: rgba(229, 191, 0, 1);">
							<text class="iconfont iconxiugai"></text>
							<text class="vehicle-add-button" ref='modify'>修改</text>
						</view>
					</view>
				</view>
			</view>
			<!--  -->
			<view class="sendorder-loadmore">
				<u-loadmore v-if="vehicleArrList.length!=0" :status="status" :icon-type="iconType" :load-text="loadText" />
			</view>
			<!-- 缺醒页 -->
			<view class="zanWSJ" v-if="vehicleArrList.length==0">
				<image :src="getStaticFilePath('/QXY/noData.png')"
				 alt="">
			</view>
			<u-select v-model="carTypeShow" :default-value="carTypeIndex" :list="carTypeList" @confirm="carTypeOnConfirm">
			</u-select>
			<u-popup v-model="carshow" length="100%" mode="right" @close="carclose">
				<view class="iscar-nav">
					<view class="iscar-nav-top"></view>
					<view class="iscar-nav-search">
						<view class="iscar-nav-search-btn" @click="carshow=false">
							返回
						</view>
						<view class="iscar-nav-search-ipt">
							<u-search @custom="carcustom" @change="valChange" v-model="carSearch" :show-action="true" action-text="搜索"
							 :action-style="actionStyle"></u-search>
						</view>
					</view>
				</view>
				<view class="iscar-content">
					<view class="iscar-content-li" v-if="carnumlist.length!=0">
						<view v-for="(item, index) in carnumlist" :key="index" @click="cusListChange(item)">{{item.name}}</view>
					</view>
					<view class="zanWSJ" v-if="carnumlist.length==0">
						<image :src="getStaticFilePath('/QXY/noData.png')" alt="">
					</view>
					<!-- <u-checkbox-group :wrap="true" @change="checkboxGroupChange">
						<u-checkbox v-model="item.checked" v-for="(item, index) in carnumlist" :key="index" :name="item.name">{{item.name}}</u-checkbox>
					</u-checkbox-group> -->
				</view>
			</u-popup>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: JSON.parse(uni.getStorageSync('userinfo')),
				background: {
					backgroundColor: '#00AAF2',
				},
				status: 'loading',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				countpage: 1,
				page: 1,
				// 客户搜索
				actionStyle: {
					backgroundColor: '#00a1f1',
					color: '#FFF',
					width: '100rpx',
					height: '60rpx',
					lineHeight: '60rpx',
					borderRadius: '15rpx',
					margin: '0 20rpx',
				},
				cusName: '请输入客户名称',
				carshow: false,
				carnumlist: [],
				carSearch: '',
				// 
				vehicleArrList: [],
				carID: '', //车辆ID
				SETTB402ID: '',
				
			}
		},
		onShow() {
			
			this.vehicleArrList = []
			this.page = 1
			this.countpage = 1
			this.dataList();
		},
		onReachBottom() {
			if (this.page == this.countpage) {
				return this.status = "nomore"
			}
			this.page++
			this.dataList()
		},
		methods: {
			modify(item) {
				uni.navigateTo({
					url: '../customerManagementModify/index' +
						`?nameIpt=${item.ORMTB410CA00}&phoneIpt=${item.ORMTB410CA02}&nameAbbreviation=${item.ORMTB410CA01}&ORMTB410ID=${item.ORMTB410ID}`
				})
			},
			//添加
			addCar() {
				uni.navigateTo({
					url: '../customerManagementAdd/index'
				})
			},
			dataList() {
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				this.status = "loading"
				if(this.cusName=='请输入客户名称'||this.cusName=='全部客户'){
					var cusName=''
				}else{
					var cusName=this.cusName
				}
				uni.request({
					url: this.baseUrl + '/orm/ormtb410/selectOrmtb410ListById',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB410CA00: cusName,
						ORMTB400ID: this.userinfo.ORMTB400ID, //二级客户id
						page: this.page,
						limit: 10,
					},
					success: (res) => {
						uni.hideLoading();
						console.log(res);
						if (res.data.code == 200) {
							if (!res.data.data || res.data.data == null) {
								this.vehicleArrList = []
								this.page = 1
								this.countpage = 1
								return
							}
							var data = res.data.data || []
							if (this.page > 1) {
								this.vehicleArrList = [...this.vehicleArrList, ...data]
							} else {
								this.vehicleArrList = data
							}
							this.countpage = Math.ceil(res.data.count / 10)
						} else {
							this.vehicleArrList = []
							this.page = 1
							this.countpage = 1
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
						if (this.countpage == this.page) {
							this.status = "nomore"
						} else {
							this.status = "loadmore"
						}
					},
					fail: (res) => {
						if (this.countpage == this.page) {
							this.status = "nomore"
						} else {
							this.status = "loadmore"
						}
						uni.hideLoading();
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},
			searchPOST() {
				this.carnumlist = []
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/orm/ormtb410/selectOrmtb410CA00ById',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB410CA00: this.carSearch,
						ORMTB400ID: this.userinfo.ORMTB400ID, //大客户ID
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							var data = res.data.data
							if (!res.data.data || res.data.data == null) {
								this.carnumlist = []
							} else {
								this.carnumlist = [{
										id: '',
										name: '全部客户',
									}]
								data.forEach(item => {
									this.carnumlist.push({
										id: item.ORMTB410ID,
										name: item.ORMTB410CA00,
									})
								})
							}
			
						}
						uni.hideLoading();
					},
					fail: (res) => {
						uni.hideLoading();
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
					}
				});
			},
			carcustom() {
				this.searchPOST();
			},
			valChange() { //输入input发生变化
				this.carnumlist = []
				this.carSearch = this.carSearch.toUpperCase()
				this.searchPOST();
			},
			cusQueryClick() {
				this.carshow = true
				this.searchPOST();
			},
			cusListChange(item) {
				this.cusName = item.name
				this.dataList()
				this.carshow = false
			},
			carclose() {
				this.carSearch = ''
			},
		}
	}
</script>

<style scoped>
	.slot-wrap {
		display: flex;
		align-items: center;
		/* 如果您想让slot内容占满整个导航栏的宽度 */
		/* flex: 1; */
		/* 如果您想让slot内容与导航栏左右有空隙 */
		/* padding: 0 30rpx; */
	}

	.u-navber-search {
		width: 480rpx;
		height: 60rpx;
		background: #FFFFFF;
		border-radius: 33rpx;
		margin-left: 40rpx;
	}
	.u-navber-search text{
		line-height: 60rpx;
		padding: 0 20rpx;
	}

	.sendorder-loadmore {
		padding: 20rpx 0 20rpx 0;
	}

	.vehicle .zanWSJ {
		padding-top: 200rpx;
	}

	.vehicle .zanWSJ>image {
		display: block;
		margin: 0 auto;
		height: 360rpx;
		width: 43%;
	}


	.vehicle {
		width: 100%;
		min-height: 100vh;
		background-color: rgba(242, 242, 242, 1);
		overflow: hidden;
	}

	/* 列表 */

	.vehicle .vehicle-car {
		width: 100%;
		background: rgba(255, 255, 255, 1);
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 24rpx;
	}

	.vehicle .vehicle-car-box {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.vehicle .vehicle-stick {
		width: 6rpx;
		height: 29rpx;
		display: inline-block;
		background: linear-gradient(0deg, rgba(57, 163, 216, 1), rgba(35, 199, 217, 1));
		border-radius: 8px;
		margin-right: 16rpx;
		line-height: 29rpx;
		position: relative;
		top: 2rpx;
	}

	.vehicle .vehicle-car-details {
		font-size: 32rpx;
		color: rgba(51, 51, 51, 1);
		height: 29rpx;
		line-height: 29rpx;
		/* height: 0.37rem;
	  line-height: 0.37rem; */
	}

	/* 添加 */
	.vehicle-add {
		height: 44rpx;
		font-size: 28rpx;
		color: rgba(255, 254, 254, 1);
		background: rgba(0, 160, 241, 1);
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.vehicle .icontianjia,
	.vehicle .iconxiugai,
	.vehicle .iconbaocun,
	.vehicle .iconshanchu,
	.vehicle .iconqiyong {
		font-size: 26rpx;
		padding-left: 10rpx;
	}

	.vehicle-add-button {
		padding: 0 10rpx;
	}

	/* 内容 */
	.vehicle-content-box {
		width: 100%;
		background: rgba(255, 255, 255, 1);
	}

	.vehicle .vehicle-content {
		margin-top: 8rpx;
		border-bottom: 2rpx solid rgba(230, 230, 230, 1);
	}

	.vehicle .vehicle-carNumber {
		font-size: 30rpx !important;
		font-weight: bold;
	}

	.vehicle .vehicle-bottom view:nth-child(3)>view:first-child text:first-child {}

	.vehicle .vehicle-button-box {
		display: flex;
		justify-content: flex-end;
		padding: 30rpx 0;
	}

	.vehicle-button-margin {
		margin-right: 20rpx;
	}

	.vehicle-content-bottom {
		padding: 0 24rpx;
	}

	.vehicle-carName-phone {
		border-bottom: 2rpx solid rgba(230, 230, 230, 1);
		display: flex;
		justify-content: space-between;
		padding: 18rpx 0;
	}

	.vehicle input {
		display: inline-block;
		margin-bottom: 0 !important;
		padding: 0 !important;
		height: 43rpx !important;
		margin-left: 7rpx;
		color: rgba(51, 51, 51, 1);
		font-size: 30rpx;
		text-align: center;
		border: 2rpx solid rgba(0, 0, 0, .2);
		border-radius: 6rpx;
	}

	.inputBorder {
		border: none !important;
		text-align: left !important;
	}

	.vehicle-input-one {
		width: 166rpx !important;
	}

	.vehicle-input-two {
		width: 190rpx !important;
	}

	.vehicle-phone {
		width: 142rpx;
		display: inline-block;
		font-size: 30rpx;
		color: rgba(153, 153, 153, 1);
	}

	.vehicle-tare {
		padding: 18rpx 0;
	}

	.vehicle-dun {
		color: rgba(51, 51, 51, 1);
		font-size: 30rpx;
	}
	/* 客户搜索 */
	.iscar-nav {
		position: fixed;
		top: 0;
		width: 100%;
		height: 18vh;
		box-sizing: border-box;
		z-index: 2;
	}
	
	.iscar-content {
		margin-top: 18vh;
	}
	
	.iscar-content-li view {
		padding: 0 30rpx;
		line-height: 60rpx;
		border-bottom: 1px solid rgba(153, 153, 153, 0.3);
	}
	
	.iscar-nav-top {
		height: 10vh;
		background-color: #e3e3e3;
	}
	
	.iscar-nav-search {
		display: flex;
		background-color: #e3e3e3;
		padding-bottom: 20rpx;
	}
	
	.iscar-nav-search-ipt {
		flex: 1;
	}
	
	.iscar-nav-search-btn {
		width: 100rpx;
		height: 60rpx;
		line-height: 60rpx;
		font-size: 32rpx;
		text-align: center;
		color: #333;
		margin: 0 20rpx;
	}
	
	.iscar-nav-btn {
		display: flex;
		justify-content: space-between;
		height: 70rpx;
		line-height: 70rpx;
		font-size: 34rpx;
		color: #333;
		padding: 0 20rpx;
		border: 2rpx solid #e3e3e3;
		background-color: #fff;
	}
	
	.iscar-nav-btn view+view {
		color: #02a2f4;
	}
	
	.iscar-nav-btn view {
		width: 100rpx;
		text-align: center;
	}
	
	.sendcar-addcar {
		padding: 20rpx 20rpx;
		color: #02a2f4;
		font-size: 30rpx;
		background-color: #fff;
	}
	
	.sendcar-bottom-height {
		height: 120rpx;
	}
	
	.sendcar-bottome-nav {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		display: flex;
		height: 120rpx;
		overflow: hidden;
		box-sizing: border-box;
		z-index: 2;
		background-color: #fff;
	}
	
	.sendcar-bottome-nav-l {
		flex: 1;
		text-align: right;
		padding-right: 20rpx;
		margin-top: 20rpx;
	}
	
	.sendcar-bottome-nav-l-t {
		height: 40rpx;
		font-size: 38rpx;
		color: #333;
		overflow: hidden;
	}
	
	.sendcar-bottome-nav-l-b {
		height: 40rpx;
		overflow: hidden;
		font-size: 28rpx;
		color: #999;
	}
	
	.sendcar-bottome-nav-l-b text {
		margin-right: 10rpx;
	}
	
	.sendcar-bottome-nav-r>button {
		display: inline-block;
		height: 120rpx;
		line-height: 120rpx;
		color: #FFF;
		background-color: #02a2f4;
		/* background-color: #e5c000; */
		font-size: 36rpx;
	}
	
	.sendcar-bottome-nav-r>button+button {
		background-color: #02a2f4;
		margin-left: 5rpx;
	}
</style>
